package com.example.shopping.gouwu.mapper;


import com.example.shopping.gouwu.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GouwuMapper {
    //查询主页轮播图
    @Select("select * from homepage")
    List<Homepage> getMyHomepageList();

    //查询多少条数据
    @Select("select count(*) from goods")
    int getMyGoodsList();

    //查询商品大类
    @Select("select * from category")
    List<Category> getCategoryList();

    //删除商品大类
    @Delete("DELETE FROM category where id=#{id}")
    int DeleCategory(int id);

    //添加商品大类
    @Insert("insert into category\n" +
            "(id,parentid,name,iconurl,sortorder,level) \n" +
            "values\n" +
            "(null,#{parentid},#{name},#{iconurl},#{sortorder},#{level})")
    int AddCategory(Category category);

    //修改商品大类
    @Update("UPDATE category SET parentid=#{parentid},name=#{name},sortorder=#{sortorder},level=#{level},updated=#{updated} where id=#{id}")
    int UpCategory(Category category);

    //修改商品大类图片
    @Update("UPDATE category SET iconurl=#{iconurl},updated=#{updated} where id=#{id}")
    int UpCategoryiconurl(Category category);

    //修改商品大类状态
    @Update("UPDATE category SET cstatus=#{cstatus} where id=#{id}")
    int UpCstatus(int cstatus,int id);

    //用id查询商品大类
    @Select("select * from category where id=#{id}")
    Category getCategoryIDList(int id);

    //使用商品大类的 productid 查询该大类的商品
    @Select("select * from goods where productid=#{productid}")
    List<Goods> getDlGoods(int productid);

    //查询所有商品
    @Select("select * from goods")
    List<Goods> getGoodsList();

    //查询多少条数据
    @Select("SELECT * FROM goods ORDER BY id desc LIMIT 1;")
    Goods getGoodsdescList();

    //模糊查询商品
    @Select("select * from goods where name like '%${name}%' ")
    List<Goods> getGoodsLike(String name);

    //分页查询商品
    @Select("select * from goods limit #{currPage},#{pageSize}")
    List<Goods> getFyGoodsList(@Param("currPage") int currPage,@Param("pageSize") int pageSize);

    //查询？条商品
    @Select("SELECT * FROM goods   LIMIT #{tk}")
    List<Goods> getTkGoodsList(int tk);

    //用id查询购物商品
    @Select("select * from goods where id=#{id}")
    Goods getIDgoodsList(int id);

    //添加商品的轮播图
    @Insert("insert into goodsimage\n" +
            "(id,goodsid,goodsimages) \n" +
            "values\n" +
            "(null,#{goodsid},#{goodsimages})")
    int AddGoodsimage(Goodsimage goodsimage);

    //通过商品id查询轮播图
    @Select("select * from goodsimage where goodsid=#{goodsid}")
    List<Goodsimage> getGoodsimageList(int goodsid);

    //删除商品
    @Delete("DELETE FROM goodsimage where goodsid=#{goodsid}")
    int DeleGoodsimage(int goodsid);

    ////添加商品
    //@Insert("insert into goodsimage\n" +
    //        "(id,goodsid,goodsimages) \n" +
    //        "values\n" +
    //        "(null,8888,\"ashdaskdhakshkdhkas\")")
    //int AddGoodsimage(Goodsimage goodsimage);

    //添加商品
    @Insert("insert into goods\n" +
            "(id," +
            "name," +
            "productid," +
            "iconurl," +
            "detail," +
            "specparam," +
            "price," +
            "stock) \n" +
            "values\n" +
            "(null,#{name},#{productid},#{iconurl},#{detail},#{specparam},#{price},#{stock})")
    int AddGoods(Goods goods);

    //删除商品
    @Delete("DELETE FROM goods where id=#{id}")
    int DeleGoods(int id);

    //修改商品
    @Update("UPDATE goods SET name=#{name},productid=#{productid},detail=#{detail},specparam=#{specparam},price=#{price},stock=#{stock},updated=#{updated} where id=#{id}")
    int UpGoods(Goods goods);

    //修改商品
    @Update("UPDATE goods SET iconurl=#{iconurl},updated=#{updated} where id=#{id}")
    int UpGoodsiconurl(Goods goods);

    //收藏
    @Select("select * from collection")
    List<Collection> getCollectionList();

    //用户查询收藏
    @Select("select * from collection where userid=#{userid} ")
    List<Collection> getCollectionIdList(int userid);

    //添加收藏
    @Insert("insert into collection\n" +
            "(id,productid,userid) \n" +
            "values\n" +
            "(null,#{productid},#{userid})\n")
    int AddCollection(Collection collection);

    //删除收藏
    @Delete("DELETE FROM collection where id=#{id}")
    int DeleCollection(int id);
}
